///////////////////////////////////////////////////////////////////////////////
///广告弹出自动关闭
/// idea: setInterval()、clearInterval()

function advertisementClose(time) {
    var date = new Date();
    var endTime = date.getTime() + (time * 1000);
    function update(){
        var date = new Date();
        var nowTime = date.getTime();
        var timeDiff = Math.round((endTime - nowTime)/1000);
        document.getElementById('advertisement').innerHTML = '广告倒计时' + timeDiff;
        if (timeDiff < 0) {
            advertisement.style.display='none';     //关闭 advertisement 标签
            clearInterval(countDown);   //清除 setInterval函数
        }
    }
    update();
    var countDown = setInterval(function(){
        update();
    }, 500)
}
advertisementClose(5)
